/**
 * BanBu_QuestionOfAlbumViewController
 * @description 本文件提供相册回答问题的界面
 * @package
 * @author 		yinlinlin
 * @copyright
 * @version 		1.0
 * @description 本文件提供相册回答问题的界面
 */

#import "BanBu_QuestionOfAlbumViewController.h"

@interface BanBu_QuestionOfAlbumViewController ()

@end

@implementation BanBu_QuestionOfAlbumViewController

- (void)dealloc
{
    self.questionAndanswerCallBack = nil;
    [_lastquestionStr release];
    [_lastanswerStr release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)updateLastQuestion:(NSString *)question andAnswer:(NSString *)answer
{
    _lastanswerStr = [answer retain];
    _lastquestionStr = [question retain];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColorToRGB(0xf0f2f4);
    UIButton * _doneBu = [UIButton buttonWithType:UIButtonTypeCustom];
    [_doneBu setTitle:@"完成" forState:UIControlStateNormal];
    [_doneBu setTintColor:[UIColor whiteColor]];
    [_doneBu setFrame:CGRectMake(0, 0, 45, 35)];
    _doneBu.titleLabel.font = [UIFont systemFontOfSize:16.0];
    [_doneBu addTarget:self action:@selector(questionhaveDone) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * doneItem = [[UIBarButtonItem alloc]initWithCustomView:_doneBu];
    self.navigationItem.rightBarButtonItem = doneItem;
    [doneItem release];
    
    self.title = @"设置问题";
    
    //添加输入背景
    UIImageView * inputImgV = [[UIImageView alloc]initWithFrame:CGRectMake(21, 20, 278, 120)];
    UIImage * inputBackImg = [UIImage imageNamed:@"global_input.png"];
    inputImgV.image = [inputBackImg resizableImageWithCapInsets:UIEdgeInsetsMake(12.0, 30.0, 12.0, 30.0)];
    [self.view addSubview:inputImgV];
    [inputImgV release];
    [self.view addSubview:[BanBu_CommentMethod cuttingLineWithOriginx:22 andOriginY:80]];
    
    UILabel * questLabel = [[UILabel alloc]initWithFrame:CGRectMake(35, 41, 35, 18)];
    questLabel.text = @"问题";
    [self.view addSubview:questLabel];
    [questLabel release];
    questLabel.font = [UIFont systemFontOfSize:13.0];
    
    _questionField = [[UITextField alloc]initWithFrame:CGRectMake(73, 41, 200, 18)];
    _questionField.placeholder = @"如:我的手机号码是?";
    if (_lastquestionStr.length > 0)
    {
        _questionField.text = _lastquestionStr;
    }
    _questionField.delegate = self;
    _questionField.returnKeyType = UIReturnKeyDone;
    _questionField.font = [UIFont systemFontOfSize:13.0];
    [self.view addSubview:_questionField];
    [_questionField release];
    
    UILabel * answerLabel = [[UILabel alloc]initWithFrame:CGRectMake(35, 101, 35, 18)];
    answerLabel.text = @"答案";
    [self.view addSubview:answerLabel];
    [answerLabel release];
    answerLabel.font = [UIFont systemFontOfSize:13.0];
    
    _answerField = [[UITextField alloc]initWithFrame:CGRectMake(73, 101, 200, 18)];
    [self.view addSubview:_answerField];
    if (_lastanswerStr.length > 0)
    {
        _answerField.text = _lastanswerStr;
    }
    _answerField.delegate = self;
    _answerField.returnKeyType = UIReturnKeyDone;
    _answerField.font = [UIFont systemFontOfSize:13.0];
    [_answerField release];
}

#pragma mark - 完成查看相册的问题
- (void)questionhaveDone
{
    if ((_questionField.text.length > 0) && (_answerField.text.length > 0))
    {
        if (_questionAndanswerCallBack)
        {
            _questionAndanswerCallBack(_questionField.text,_answerField.text);
        }
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"问题或答案为空，请填写完整" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
        [alert release];
        
    }
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
